import request from '@/utils/request'

// 获得文章类型list
export async function getArticleTypeList() {
  return await request({
    url: '/article/articleTypeList',
    method: 'get'
  })
}

// 获取文章所有类型list
export function getTypeListAll() {
  return request({
    url: '/article/getTypeListAll',
    method: 'get'
  })
}
// 根据文章类型查询文章
export async function getArticleByTypeId(data) {
  return await request({
    url: '/article/getArticleByTypeId',
    method: 'get',
    params: { id: data.id, pageIndex: data.pageIndex, pageSize: data.pageSize }
  })
}

// 添加文章类型
export function addArticleType(data) {
  return request({
    url: '/article/addArticleType',
    method: 'post',
    data
  })
}
// 删除文章类型
export function delArticleType(data) {
  return request({
    url: '/article/delArticleType',
    method: 'get',
    params: { id: data.id }
  })
}

// 发布文章
export async function publishArticle(data) {
  return await request({
    url: '/article/addArticle',
    method: 'post',
    data
  })
}

// 删除文章
export function delArticle(data) {
  return request({
    url: '/article/delArticle',
    method: 'get',
    params: { articleId: data.articleId }
  })
}

// 编辑文章
export async function editArticle(data) {
  return await request({
    url: '/article/editArticle',
    method: 'post',
    data
  })
}

// 获取文章列表
export async function findArticleList(data) {
  return await request({
    url: '/article/findArticleList',
    method: 'get',
    params: { title: data.title, username: data.username, pageIndex: data.pageNum, typeIds: data.articleType }
  })
}

// 获取我的文章
export async function myArticles(data) {
  return await request({
    url: '/article/myArticles',
    method: 'get',
    params: { userId: data.userId, pageSize: data.pageSize }
  })
}

// 根据文章id获取文章
export async function getArticleById(data) {
  return await request({
    url: '/article/articleById',
    method: 'get',
    params: { articleId: data.articleId }
  })
}

// 根据文章id获取文章点赞数
export async function getArticleLikeCount(data) {
  return await request({
    url: '/article/likeCount',
    method: 'get',
    params: { articleId: data.articleId }
  })
}

// 点赞文章
export async function doLike(data) {
  return await request({
    url: '/article/doLike',
    method: 'get',
    params: { userId: data.userId, articleId: data.articleId }
  })
}

// 取消点赞
export async function doUnLike(data) {
  return await request({
    url: '/article/doUnLike',
    method: 'get',
    params: { userId: data.userId, articleId: data.articleId }
  })
}

// 用户是否已经对该文章点赞
export async function isUserLike(data) {
  return await request({
    url: '/article/userIsLike',
    method: 'get',
    params: { userId: data.userId, articleId: data.articleId }
  })
}

// 收藏
export function collection(data) {
  return request({
    url: '/article/collection',
    method: 'get',
    params: { userId: data.userId, articleId: data.articleId }
  })
}

// 取消收藏
export function cancelCollection(data) {
  return request({
    url: '/article/cancelCollection',
    method: 'get',
    params: { userId: data.userId, articleId: data.articleId }
  })
}

// 用户是否收藏
export function isUserCollected(data) {
  return request({
    url: '/article/isUserCollected',
    method: 'get',
    params: { userId: data.userId, articleId: data.articleId }
  })
}

// 增加阅读量
export function increaseReadCount(data) {
  return request({
    url: '/article/increReadCount',
    method: 'get',
    params: { articleId: data.articleId }
  })
}

